/* ========================================
 *
 * Copyright YOUR COMPANY, THE YEAR
 * All Rights Reserved
 * UNPUBLISHED, LICENSED SOFTWARE.
 *
 * CONFIDENTIAL AND PROPRIETARY INFORMATION
 * WHICH IS THE PROPERTY OF your company.
 *
 * ========================================
*/
#include <device.h>

void main()
{
    uint32 voltageCount;
	uint32 db[5];
	uint32 inp[2];
    uint16 c=0;
	uint32 i=0;
    ADC_DelSig_1_Start();  /* Configure and power up ADC */
    LCD_Char_1_Start(); /* Initialize and clear the LCD */

    LCD_Char_1_Position(0,0); /* Move the cursor to Row 0 Column 0 */
    
    /* Print Label for the pot voltage raw count */
    LCD_Char_1_PrintString("Voltage : ");
	
    ADC_DelSig_1_StartConvert(); /* Force ADC to initiate a conversion */
	//db[0]=0111;
	//db[1]=0108;
	//db[2]=0117;
	//db[3]=0119;
	//db[4]=0205;
	while (c<=5)
    //while(1)
    {
        /* Wait for end of conversion */
        ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_WAIT_FOR_RESULT); 
        voltageCount = ADC_DelSig_1_GetResult32(); /* Get converted result */

      /* Set range limit */
      
      /* Continue on */
      if (voltageCount>0xFFFF )//|| voltageCount>0x0425 )
	  {
	  	LCD_Char_1_Position(0,9);
        voltageCount=0; //voltageCount-0xFFFF;
	  }
	  else if (voltageCount>0x00E1 && voltageCount<=0x040F )
	  {
	  	LCD_Char_1_Position(1,11);
		LCD_Char_1_PrintInt16(voltageCount);
		
		inp[c]=voltageCount;
		LCD_Char_1_Position(1,5);
		LCD_Char_1_PrintInt16(c);
		c++;
		CyDelay( 1000);
		
	  }
	
        LCD_Char_1_Position(0,9);
        LCD_Char_1_PrintInt16(voltageCount); /* Print result on LCD */
    }
	
	for(i=0;i<=1;i++)
	{
		LCD_Char_1_Position(1,0);
		LCD_Char_1_PrintInt16(inp[i]);
		CyDelay( 2000);

	}
	
	if ((inp[0]-0x0050) < inp[1] && (inp[0]+0x0050) > inp[1])
	{
		LCD_Char_1_Position(1,5);
		LCD_Char_1_PrintString("Open! ");
	}
}